package org.budo.redis.jdbc.driver.statement.key;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.budo.redis.jdbc.driver.BudoRedisJdbcConnection;
import org.budo.redis.jdbc.driver.BudoRedisJdbcPreparedStatement;
import org.budo.redis.jdbc.driver.executor.RedisStatementExecutor;
import org.budo.redis.jdbc.driver.statement.AbstractRedisStatement;

/**
 * @author lmw
 */
public class MOVE extends AbstractRedisStatement {
    @Override
    public void execute(PreparedStatement preparedStatement) throws SQLException {
        byte[] key = this.parameter(0, preparedStatement);
        Integer dbIndex = this.parameterNumber(1, preparedStatement).intValue();

        RedisStatementExecutor statementExecutor = ((BudoRedisJdbcConnection) preparedStatement.getConnection()).getStatementExecutor();
        Long move = statementExecutor.move(key, dbIndex);

        ((BudoRedisJdbcPreparedStatement) preparedStatement).setUpdateCount(move.intValue());
    }
}